<template>
	<view class="order">
		<view class="tab">
			<p @click='Switcher(0)' :class="{'p':index==0}">全部<span></span></p>
			<p @click='Switcher(1)' :class="{'p':index==1}">待付款<span></span></p>
			<p @click='Switcher(2)' :class="{'p':index==2}">待接单<span></span></p>
			<p @click='Switcher(3)' :class="{'p':index==3}">进行中<span></span></p>
			<p @click='Switcher(4)' :class="{'p':index==4}">待评价<span></span></p>
			<p @click='Switcher(5)' :class="{'p':index==5}">已取消<span></span></p>
		</view>
		<view class="main">
			<orderList v-for="(item,index) in dataList" :key="index" :item="item"></orderList>
			<image v-if="dataList.length==0" src="../../static/image.png"></image>
		</view>
	</view>
</template>

<script>
	import bus from "@/config/emit.js"
	import orderList from '../../components/order_list/order_list.vue'
	export default {
		components: {
			orderList
		},
		data() {
			return {
				falg: true,
				index: 0,
				datePage: 1,
				dataList: [],
			};
		},
		methods: {
			Switcher(index) {
				if (index !== this.index) {
					this.index = index;
					this.dataList = [];
					this.getList(index);
				}
			},
			getList(index) {
				this.$httpRequest('/order/getOrderList', {
					page: this.datePage,
					order_status: index
				}).then(res => {
					if(this.datePage==1){
						this.dataList = [];
					}
					if (res.data.last_page > res.data.current_page) {
						this.datePage++;
					} else {
						this.falg = false
					}
					this.dataList.push(...res.data.data)
				});
			},
		},
		// 触底刷新
		onReachBottom() {
			if (this.falg) {
				this.getList(this.index);
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.datePage = 1;
			this.falg = true;
			this.getList(this.index);
			uni.stopPullDownRefresh();
		},
		onShow() {
			this.datePage = 1;
			this.falg = true;
			this.getList(this.index);
		},
		onLoad() {
			bus.$on('orderForm',()=>{
				this.dataList = [];
				this.datePage = 1;
				this.falg = true;
				this.getList(this.index);
			})
		}
	}
</script>

<style lang="less">
	.order {
		min-height: 100vh;
		padding-bottom: 200rpx;
		box-sizing: border-box;

		&>.main {
			width: 690rpx;
			margin: 0 auto;

			&>image {
				width: 616rpx;
				height: 616rpx;
				display: block;
				margin: 100rpx auto 0;
			}
		}

		&>.tab {
			width: 100%;
			height: 86rpx;
			display: flex;

			&>.p {
				color: #3B7933;

				&>span {
					background: #3B7933;
				}
			}

			&>p {
				flex: 1;
				height: 100%;
				display: flex;
				font-size: 13px;
				color: #999999;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				&>span {
					width: 28rpx;
					height: 6rpx;
					background: #3B793300;
					margin-top: 6rpx;
				}
			}
		}
	}
</style>